package com.zyp.bio;


import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author zhangyanping
 */
public class BIOServer {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(9001);
            while (true){
                Socket socket =  serverSocket.accept();
                System.out.println("有人连上了服务器");
                //如失灵请自行创建thread类实现此功能
                new Thread(()->{
                    while (true){
                        try {
                            byte [] msg = new byte[1024];
                            socket.getInputStream().read(msg);
                            System.out.println("收到消息："+new String(msg));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

